#include"common.hpp"

using namespace std;


int main()
{
    //建立管道
    int ret = mkfifo(FILE_NAME, MODE);
    if(ret < 0)
    {
        perror("mkfifo");
        return -1;
    }

    //打开管道
    int fd = open(FILE_NAME, O_RDONLY);
    if(fd < 0)
    {
        perror("open");
        return -1;
    }

    //开始通信
    while(true)
    {
        char read_buffer[SIZE] = {0};
        ssize_t n = read(fd, read_buffer, sizeof(read_buffer));
        if(n < 0)
        {
            perror("read");
            return -1;
        }
        if(n == 0)
        {
            cout << "Client quit! END\n";
            break;
        }

        printf("Client: %s\n", read_buffer);
    }

    //通信结束
    close(fd);

    return 0;
}